package com.nuoniu.sibanyun.service.erp.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.entity.dto.ErpVoucherTableDto;
import com.nuoniu.sibanyun.entity.erp.ErpVoucherTable;
import com.nuoniu.sibanyun.mapper.erp.ErpVoucherTableMapper;
import com.nuoniu.sibanyun.service.erp.IErpVoucherTableService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 单据唯一code管理实体表名 服务实现类
 * </p>
 *
 * @author baiqiang
 * @since 2020-11-09
 */
@Service
public class ErpVoucherTableServiceImpl extends ServiceImpl<ErpVoucherTableMapper, ErpVoucherTable> implements IErpVoucherTableService {

    @Override
    public ErpVoucherTable getErpVoucherTable(String source) {
        QueryWrapper<ErpVoucherTable> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("voucher_type_code",source);
        ErpVoucherTable one = getOne(queryWrapper);
        return one;
    }

    @Override
    public List<ErpVoucherTable> listByDto(ErpVoucherTableDto erpVoucherTableDto) {
        QueryWrapper queryWrapper = new QueryWrapper();
        String moduleCode = erpVoucherTableDto.getModuleCode();
        String moduleName = erpVoucherTableDto.getModuleName();
        String voucherTypeCode = erpVoucherTableDto.getVoucherTypeCode();
        String voucherTypeName = erpVoucherTableDto.getVoucherTypeName();
        if(StringUtils.isNotBlank(moduleCode)){
            queryWrapper.like("module_code", moduleCode);
        }
        if(StringUtils.isNotBlank(moduleName)){
            queryWrapper.like("module_name", moduleName);
        }
        if(StringUtils.isNotBlank(voucherTypeCode)){
            queryWrapper.like("voucher_type_code", voucherTypeCode);
        }
        if(StringUtils.isNotBlank(voucherTypeName)){
            queryWrapper.like("voucher_type_name", voucherTypeName);
        }
        queryWrapper.select("module_code","module_name","voucher_type_code","voucher_type_name");
        return list(queryWrapper);
    }
}
